﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;
using VIA.Modularity;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
namespace VIA.Integration.LeadShine.Presentation
{
    [DependsOn(typeof(VIA.Integration.Presentation.IntegrationPresentationModule))]
    public class VIAIntegrationLeadShinePresentationModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddSingleton<Profile, MapperProfile>();
        }
    }
    public class MapperProfile : AutoMapper.Profile
    {
        public MapperProfile()
        {
            CreateMap<MotionPathOption, MotionPathModel>().ReverseMap();
            CreateMap<AxisModel, AxisOption>()
                .ForMember(x => x.VelocityCurve, mc => mc.MapFrom(o => o.DefaultVelocityCurve))
                .ReverseMap()
                .ForMember(x => x.DefaultVelocityCurve, (mc) => mc.MapFrom(o => o.VelocityCurve))
                .AfterMap((x, t) =>
            {
                //if (t.HomeVelocityCurve == null)
                //    t.HomeVelocityCurve = new VelocityCurveModel();
                //if (t.DefaultVelocityCurve == null)
                //    t.DefaultVelocityCurve = new VelocityCurveModel();
                foreach (var item in t.MotionPaths)
                {
                    if (item.VelocityCurve == null)
                        item.VelocityCurve = new VelocityCurveModel();
                }
            });
            CreateMap<VelocityCurve, VelocityCurveModel>().ReverseMap();
        }
    }
}
